import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
from phuce import settings

class Video:
  def __init__(self, width=None, height=None):
    settings.width = self.width = width or settings.width
    settings.height = self.height = height or settings.width
    pygame.display.init()
    pygame.display.gl_set_attribute(GL_ALPHA_SIZE, 8)
    pygame.display.gl_set_attribute(GL_DEPTH_SIZE, 1)
    pygame.display.gl_set_attribute(GL_STENCIL_SIZE, 1)
    self.surface = pygame.display.set_mode([self.width, self.height], OPENGL|DOUBLEBUF, 24)
    pygame.display.set_caption("Plugh")
    self.__init_extensions__()
    self.__init_gl__()

  def __init_extensions__(self):
    pass

  def __init_gl__(self):
    glClearColor(0, 0, 0, 0)
    glViewport(0, 0, self.width, self.height)
    glEnable(GL_SCISSOR_TEST)
    glScissor(0, 0, self.width, self.height)
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
    glShadeModel(GL_FLAT)
    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LEQUAL)
    glEnable(GL_CULL_FACE)
    glCullFace(GL_BACK)
    glFrontFace(GL_CW)
    glDisable(GL_BLEND)
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

  def __del__(self):
    pygame.display.quit()

  def flip(self):
    pygame.flip()

if __name__ == "__main__":
  v = Video()
